package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyHatchExchangeConf;
import com.sc.nft.entity.EcologyHatchMethodCollectionConf;
import com.sc.nft.entity.EcologyHatchUsePropsExchange;
import com.sc.nft.entity.EcologyPoolCommunityServiceRankIncomeConf;
import com.sc.nft.mapper.EcologyHatchUsePropsExchangeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @author 朱梦晨
 * @Description: 兑换消耗道具关联表 数据dao
 * @date 2024-08-06
 */
@Slf4j
@Repository
public class EcologyHatchUsePropsExchangeDao extends ServiceImpl<EcologyHatchUsePropsExchangeMapper, EcologyHatchUsePropsExchange> {


    /**
     * 根据熔炼兑换配置id和熔炼配置id获取列表
     *
     * @param confId
     * @param confId
     * @return
     */
    public List<EcologyHatchUsePropsExchange> getEcologyHatchUsePropsExchangeList(Long confId) {
        LambdaQueryWrapper<EcologyHatchUsePropsExchange> wrapper = new LambdaQueryWrapper<>();
        if (Objects.nonNull(confId)){
            wrapper.eq(EcologyHatchUsePropsExchange::getEcologyHatchExchangeConfId, confId);
        }
        return list(wrapper);
    }

    /**
     * 根据熔炼兑换配置id和熔炼配置id获取列表
     *
     * @param propId
     * @return
     */
    public EcologyHatchUsePropsExchange findEcologyHatchUsePropsExchangeListByPropId(Long propId,Long ecologyHatchId) {
        LambdaQueryWrapper<EcologyHatchUsePropsExchange> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchUsePropsExchange::getEcologyHatchId, ecologyHatchId);
        wrapper.eq(EcologyHatchUsePropsExchange::getPropId, propId);
        wrapper.eq(EcologyHatchUsePropsExchange::getStatus,Boolean.TRUE);
        wrapper.eq(EcologyHatchUsePropsExchange::getIsDelete,Boolean.FALSE);
        return getOne(wrapper);
    }

    /**
     * 根据熔炼兑换配置id和熔炼配置id获取列表
     *
     * @param confId
     * @return
     */
    public List<EcologyHatchUsePropsExchange> findAdminEcologyHatchUsePropsExchangeListByConfId(Long confId) {
        LambdaQueryWrapper<EcologyHatchUsePropsExchange> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(EcologyHatchUsePropsExchange::getEcologyHatchExchangeConfId, confId);
        queryWrapper.eq(EcologyHatchUsePropsExchange::getIsDelete,Boolean.FALSE);
        return baseMapper.selectList(queryWrapper);
    }


    /**
     * 根据熔炼兑换配置id和熔炼配置id获取列表
     *
     * @param confId
     * @return
     */
    public List<EcologyHatchUsePropsExchange> findEcologyHatchUsePropsExchangeListByConfId(Long confId) {
        LambdaQueryWrapper<EcologyHatchUsePropsExchange> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(EcologyHatchUsePropsExchange::getEcologyHatchExchangeConfId, confId);
        queryWrapper.eq(EcologyHatchUsePropsExchange::getStatus,Boolean.TRUE);
        queryWrapper.eq(EcologyHatchUsePropsExchange::getIsDelete,Boolean.FALSE);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 获取熔炼上限兑换关联表
     *
     * @param id
     * @param ecologyHatchId
     * @param confId
     * @return
     */
    public EcologyHatchUsePropsExchange getOneByEcologyHatchId(Long ecologyHatchId, Long confId) {
        LambdaQueryWrapper<EcologyHatchUsePropsExchange> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchUsePropsExchange::getEcologyHatchId, ecologyHatchId);
        wrapper.eq(EcologyHatchUsePropsExchange::getEcologyHatchExchangeConfId, confId);
        wrapper.eq(EcologyHatchUsePropsExchange::getStatus, Boolean.TRUE);
        wrapper.eq(EcologyHatchUsePropsExchange::getIsDelete, Boolean.FALSE);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }



    /**
     * 获取熔炼上限兑换关联表
     *

     * @param id
     * @return
     */
    public EcologyHatchUsePropsExchange getOneById(Long id) {
        LambdaQueryWrapper<EcologyHatchUsePropsExchange> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchUsePropsExchange::getId, id);
        wrapper.eq(EcologyHatchUsePropsExchange::getIsDelete,Boolean.FALSE);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }




    /**
     * 修改
     *
     * @param propId
     * @param propCount
     * @param propImage
     * @param status
     * @return
     */
    public boolean updateEcologyHatchUsePropsById(Long id, Long propId, Long propCount, String propImage, Boolean status) {
        LambdaUpdateWrapper<EcologyHatchUsePropsExchange> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchUsePropsExchange::getId, id);
        wrapper.set(EcologyHatchUsePropsExchange::getPropId, propId);
        wrapper.set(EcologyHatchUsePropsExchange::getPropCount, propCount);
        wrapper.set(EcologyHatchUsePropsExchange::getPropImage, propImage);
        wrapper.set(EcologyHatchUsePropsExchange::getStatus, status);
        return update(new EcologyHatchUsePropsExchange(), wrapper);
    }



    /**
     * 更新状态
     * @param id
     * @param status
     * @return
     */

    public boolean updateStatusById(Long id, Boolean status) {
        LambdaUpdateWrapper<EcologyHatchUsePropsExchange> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchUsePropsExchange::getId, id);
        wrapper.set(EcologyHatchUsePropsExchange::getStatus, status);
        return update(new EcologyHatchUsePropsExchange(), wrapper);
    }

    public boolean dealExchangeUsePropsById(Long id) {
        return removeById(id);
    }

}
